<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Data extends Controller {

    public function __construct() {
        parent::__construct();

//        echo 'dashboard ctrl';

        Session::init();

        $loggeg = Session::get('loggedIn');
        $role = Session::get('role');


        if ($loggeg == false || $role != 'User') {
            Session::Destroy();
            header('location: ' . URL . 'error/index');
            exit;
        }
//        print_r($_SESSION['role']);
    }

    public function index() {
//        $item = 10;
//        $start = ($x - 1) * 10;

        $this->view->dataList = $this->model->dataList();

//        $this->view->page = $this->model->page();

        $this->view->render('data/index');
    }

    public function upload() {

        $this->view->render('data/upload');
    }

//    public function save() {
//
//        $file_name = $_FILES['upload']['name'];
//
//        $source = $_FILES['upload']['tmp_name'];
//
//        $this->view->save = $this->model->save($file_name, $source);
//
//        $this->view->dataList = $this->model->dataList();
//        $this->view->render('data/index');
//    }

    public function read() {

        $this->view->read_ext = $this->model->read_ext();

        if ($this->view->read_ext == true) {

            $this->view->readExcel = $this->model->readExcel();


            $this->view->render('data/read');
        } else {

            $this->view->render('data/error');
        }
    }

    public function delete($id) {

        $this->view->deletedata = $this->model->deleteData($id);
        header('location:' . URL . 'data');
    }

    public function simpan() {

        $this->model->simpan();
    }

    public function edit($id) {

        $this->view->edit = $this->model->edit($id);
//        print_r($id);
        $this->view->render('data/edit');
    }

    public function edit_save() {
        $data['kd_makul'] = $_POST['kd_makul'];
        $data['nilai'] = $_POST['nilai'];

//        print_r($id);
//        print_r($nilai);
        $this->model->edit_save($data);
        header('location:' . URL . 'data');
    }

    public function save_data() {

        $data['kd_makul'] = $_POST['kd_makul'];
        $data['nilai'] = $_POST['nilai'];

//        var_dump($data);
        $this->model->save_data($data);

        header('location:' . URL . 'data');
    }

    public function add_data() {
        $this->view->list_makul = $this->model->list_makul();
        $this->view->render('data/dataform');
    }

}

?>
